<%@ include file="/common/taglibs.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="catalog" tagdir="/WEB-INF/tags/catalog"%>
<title><fmt:message key="news.subscription.title" /></title>
<content tag="position">
	<fmt:message key="accountMenu.serviceCenter" />
	&gt;
	<b><fmt:message key="news.subscription.name" /> </b>
</content>



	<div class="subscribe_wrap">
		<div class="top">
			<b><fmt:message key="news.subscription.subscriptionIsFree" /> </b>
			<br />
			<fmt:message key="news.subscription.subscriptionDeclare" />
			<a href="<catalog:contentCategoryUrl categoryCode="privacy"/>" target="_blank"> <fmt:message
					key="helpCenter.privacy.title" /> </a>

			<br />
			<br />
		</div>
		<div class="content">
			<form name="subscribeForm" id="subscribeForm" method="post" onsubmit="return validateFormWithMsg(this);">
				<input type="hidden" name="doAction" value="subscribe"/>
				<ul class="title clearfix">
					<li>
						<fmt:message key="news.subscription.subscribe" />
					</li>
				</ul>
				<div class="desc">
					<c:if test="${not empty newsletterGroupList}">
						<input type="checkbox" name="checkAll" id="checkAll" onclick="toggleSelectAll(this);">
						<b><fmt:message key="news.subscription.selectAll" /> </b>
					</c:if>
					<c:if test="${empty newsletterGroupList}">
						<span class="cRed"><fmt:message key="news.subscription.empty" /> </span>
					</c:if>
					<br>
					<c:forEach var="item" items="${newsletterGroupList}">
						<span name="subscriptGroupSpan" class="spanNoBr">
							 <input type="checkbox"	name="newsletterGroupId" value="${item.newsletterGroupId}"/> ${item.name}
						</span>
					</c:forEach>
					<div>
						<fmt:message key="address.email" />:
						<span><input name="subscribe_email" id="subscribe_email" type="text" class="inputtxt"	style="width: 150px" value="${email}" /></span>
						<a href="javascript:void(0)" onclick="subscribe();return false;" class="btn_02"><span><fmt:message
									key="news.subscription.subscribe" /> </span> </a>
						<fmt:message key="news.subscription.subscribeInfo" />
					</div>
				</div>
			</form>
			<form name="cancelSubscribeForm" id="cancelSubscribeForm" method="post" onsubmit="return validateFormWithMsg(this);">
				<input type="hidden" name="doAction" value="cancelSubscribe"/>
				<ul class="title clearfix">
					<li>
						<fmt:message key="news.subscription.unsubscribe" />
					</li>
				</ul>
				<div class="desc">
					<div>
						<fmt:message key="news.subscription.unsubscriptionDeclare" />
					</div>
					<div>
						<fmt:message key="address.email" />:
						<span><input name="unsubscribe_email" id="unsubscribe_email" type="text" class="inputtxt" 	style="width: 150px" value="" /></span>
						<a href="javascript:void(0)" onclick="cacnelSubscribe();return false;" class="btn_02"><span><fmt:message
									key="news.subscription.unsubscribe" /> </span> </a>
						<fmt:message key="news.subscription.unsubscribeInfo" />
					</div>
				</div>
			</form>
		</div>
	</div>
</form>

<script type="text/javascript">
function toggleSelectAll(obj){
	$j('#subscribeForm input[@name="newsletterGroupId"][type="checkbox"]').attr('checked',obj.checked);
}

$j(document).ready(function () {
	applyValidate($('subscribe_email'),"required,email");
	applyValidate($('unsubscribe_email'),"required,email");
	$j('#subscribeForm input[@name="newsletterGroupId"][type="checkbox"]').click(function(){
		if(!$j(this).get(0).checked){
			$j('#checkAll').get(0).checked= false;
		}
	});
});

function subscribe(){
	var form = $('subscribeForm');
	if(validateFormWithMsg(form)){
		form.submit();
	}
}
function cacnelSubscribe(){
	var form = $('cancelSubscribeForm');
	if(validateFormWithMsg(form)){
		form.submit();
	}
}
</script>